<?php
/**
* Class DeleteFile into Bo Controller
* @author SillySmart
* @copyright SillySmart
* @package Mvc.Controllers.Bo
* @see Mvc.Controllers.Bo.ControllerProtected
* @see Mvc.Controllers.SiteProtected
* @see Sls.Controllers.Core.SLS_GenericController
* @since 1.0
*
*/
class BoDeleteFile extends BoControllerProtected
{
	public function init()
	{
		parent::init();
	}

	public function action()
    {
		// Params
		$action = $this->_http->getParam("action");
		$id 	= $this->_http->getParam("id");
		$db 	= $this->_http->getParam("db");
		$table 	= $this->_http->getParam("table");
		$column = $this->_http->getParam("column");
		$type 	= $this->_http->getParam("type");

		// Check account rights
		$right = SLS_BoRights::isAuthorized("delete",ucfirst($db)."_".SLS_String::tableToClass($table));
		if ($right == -1)
			$this->_generic->redirect("Bo/Connection.sls");
		else if ($right == 0)
			$this->_generic->redirect("Bo/".ucfirst(strtolower($action)).ucfirst($db)."_".SLS_String::tableToClass($table)."/id/".$id.".sls");
		// /Check account rights

		// Delete specific type files
		$this->_generic->useModel($table,$db);
		$className = ucfirst($db)."_".SLS_String::tableToClass($table);
		$object = new $className();
		if ($object->getModel($id))
		{
			$object->deleteFiles(array($column));
			$functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",$column)," ",false)),"");
			$object->{$functionName}("");
			$object->save();
		}

		// Forward
		$this->_generic->redirect("Bo/".ucfirst(strtolower($action)).ucfirst($db)."_".SLS_String::tableToClass($table)."/id/".$id.".sls");
    }
}
?>